/**
 * Created by Administrator on 2016/5/9.
 */

//调用mysql模块
var mysql=require('mysql');
var moment = require('moment');
//创建一个connection
var connection = mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'',
    database:'vshow',
    port:'3306'
});

////创建一个connection
//connection.connect(function(err){
//    if(err){
//        console.log('[query] - :'+err);
//    }else{
//        console.log('connect succeed!');
//    }
//});

//设置峰值方法
//function setonlinemax(room_name,online_num){
//    var date = new Date();
//    var year = date.getFullYear();
//    var month = date.getMonth()+1;
//    var day = date.getDate();
//    var datestr=year+'/'+month+'/'+day+' 00:00:00';
//    var timestamp = new Date(datestr).getTime();
//    var time1 = parseInt(timestamp/1000);//当天开始时间戳
//    var time2 = time1 + 24*60*60;//当天结束时间戳
//    var timestamp2 =  new Date().getTime();
//    var time = parseInt(timestamp2/1000);//当前时间戳
//    var online_num = online_num;
//
//    //历史峰值
//    connection.query('SELECT * FROM roomonline WHERE room_name = "'+room_name+'" AND update_time BETWEEN '+time1+' AND '+time2,function(err, results) {
//
//        if(!results[0]){
//            connection.query('INSERT INTO roomonline (room_name,online_num,update_time)VALUES("'+room_name+'","'+online_num+'","'+time+'")',function(err2, results2){
//                if(err2){
//                    console.log(err2);
//                }
//            });
//        }else{
//            if(online_num>results[0].online_num){
//                connection.query('UPDATE roomonline SET online_num='+online_num+' WHERE online_id='+results[0].online_id,function(err3, results3){
//                    if(err3){
//                        console.log(err3);
//                    }
//                });
//            }
//        }
//    });
//}

//
//var date = new Date();
//var year = date.getFullYear();
//var month = date.getMonth()+1;
//var day = date.getDate();
//var datestr=year+'/'+month+'/'+day+' 00:00:00';
//var timestamp = new Date(datestr).getTime();
//var time1 = parseInt(timestamp/1000);
//var time2 = time1 + 24*60*60;
//var timestamp2 =  new Date().getTime();
//var time = parseInt(timestamp2/1000);
//var online_max=0;

var moment = require('moment');
var time = moment().unix();//当前时间的时间戳
var time1 = moment(moment().format('YYYY-MM-DD')).unix();//今天的零点时间戳
var time2 = time1 + 24*60*60;//明天的零点时间戳

console.log(time);
console.log(time1);
console.log(time2);


//执行sql语句

//connection.query('INSERT INTO roomonline (room_name,online_num,update_time)VALUES("room001","1","'+time+'")',function(err2, results2){
//    if(err2){
//        console.log(err2)
//    }else{
//        console.log(results2+'111');
//    }
//});
//关闭connection
//connection.end(function(err){
//    if(err){
//        return;
//    }
//    console.log('[connection end] succeed!');
//});